package com.gyg.service.impl;

import com.gyg.constant.CloudConstant;
import com.gyg.domain.*;
import com.gyg.dao.CloudAudioMapper;
import com.gyg.returns.RespCode;
import com.gyg.returns.RespEntity;
import com.gyg.returns.RespTable;
import com.gyg.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyg.vo.PageVO;
import com.gyg.vo.param.*;
import com.gyg.vo.result.AudioResult;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 音频信息表 服务实现类
 * </p>
 *
 * @author gyg
 * @since 2021-04-14
 */
@Service
public class CloudAudioServiceImpl extends ServiceImpl<CloudAudioMapper, CloudAudio> implements CloudAudioService {

    @Override
    public RespTable<List<AudioResult>> audioList(FileParam fileParam) {
        Integer count = baseMapper.audioCount(fileParam);

        if (Objects.isNull(count) || 0 == count) {
            return new RespTable<>(RespCode.OK, new ArrayList<>(), 0);
        }

        PageVO pageVO = new PageVO(fileParam.getPage(), fileParam.getLimit(), count);
        fileParam.setPage(pageVO.getBegin() - 1);
        List<AudioResult> audioResultList = baseMapper.audioList(fileParam);

        return new RespTable<>(RespCode.OK, audioResultList, count);
    }

    @Override
    public RespEntity banAudio(BanParam banParam) {
        CloudAudio cloudAudio = CloudAudio
                .builder()
                .id(banParam.getFileId())
                .audioBan(1)
                .audioImg(CloudConstant.SYSTEM_BAN)
                .build();
        baseMapper.updateById(cloudAudio);

        return new RespEntity(RespCode.SUCCESS);
    }

    @Override
    public RespEntity unsealAudio(BanParam banParam) {
        CloudAudio cloudAudio = CloudAudio.builder()
                .id(banParam.getFileId())
                .audioBan(0)
                .audioImg(CloudConstant.SYSTEM_AUDIO)
                .build();
        baseMapper.updateById(cloudAudio);

        return new RespEntity(RespCode.SUCCESS);
    }

}
